package Practice2;

import java.io.*;
import java.util.Scanner;

public class IOPractice3 {
    public static void main(String[] args) throws IOException {
        //第一遍
        //PWDemo2写记事本
        FileOutputStream fos1 = new FileOutputStream("fos1.txt");
        OutputStreamWriter osw1 = new OutputStreamWriter(fos1);
        BufferedWriter bw1 = new BufferedWriter(osw1);
        PrintWriter pw1 = new PrintWriter(bw1,true);

        Scanner scan1 = new Scanner(System.in);
        System.out.println("记事本已打开，输入exit退出！");
        while(true) {
            System.out.println("请输入本行内容：");
            String line = scan1.nextLine();
            if("exit".equals(line)) {
                break;
            }
            pw1.println(line);
        }
        pw1.close();

        //BRDemo读记事本
        FileInputStream fis1 = new FileInputStream("fos1.txt");
        InputStreamReader isr1 = new InputStreamReader(fis1);
        BufferedReader br1 = new BufferedReader(isr1);
        String str;
        while((str = br1.readLine())!=null) {
            System.out.println(str);
        }
        br1.close();

        //第二遍
        //PWDemo2写记事本
//        FileOutputStream fos2 = new FileOutputStream("fos2.txt");
//        OutputStreamWriter osw2 = new OutputStreamWriter(fos2);
//        BufferedWriter bw2 = new BufferedWriter(osw2);
//        PrintWriter pw2 = new PrintWriter(bw2,true);
//
//        Scanner scan2 = new Scanner(System.in);
//        System.out.print("请输入内容（输入exit退出）：");
//        while(true) {
//            String str2 = scan2.nextLine();
//            if("exit".equals(str2)) {
//                break;
//            }
//            pw2.println(str2);
//        }
//        pw2.close();
//
//        //BRDemo读记事本
//        FileInputStream fis2 = new FileInputStream("fos2.txt");
//        InputStreamReader isr2 = new InputStreamReader(fis2);
//        BufferedReader br2 = new BufferedReader(isr2);
//        String str;
//        while((str = br2.readLine())!=null) {
//            System.out.println(str);
//        }
//        br2.close();
    }
}
